Includes a subquery into the incremental maintenance mechanism of a view.

Namespace:  C1.LiveLinq.LiveViews
Assembly:  C1.Silverlight.LiveLinq (in C1.Silverlight.LiveLinq.dll)

Syntax

C#
public View<TResult> AttachView<TResult>(
	Func<View<T>, View<TResult>> selector
)
Visual Basic
Public Function AttachView(Of TResult) ( _
	selector As Func(Of View(Of T), View(Of TResult)) _
) As View(Of TResult)

Parameters

selector
Type: System..::..Func<(Of <(<'View<(Of <(<'T>)>)>, View<(Of <(<'TResult>)>)>>)>)>
A function to obtain the attached subview from the view to which it is attached.

Type Parameters

TResult
The type of the elements in the subquery view.

Return Value

The attached subview.

Remarks

Subquery is a query inside a function that is a part of an outer query. If the outer query is a live view, and its base data changes so it needs to recompute the function, by default it just evaluates the function, which means creating a new view object for the subquery on every such recomputation. To improve performance by avoiding repeated creation and population of subviews, use the AttachView method to make the outer view aware of its subview. Then the outer view will cache and reuse subview objects it creates.

If there are more than one subviews attached to a single view, every subview must be supplied with a unique subview id by using the AttachView overload with subviewId parameter.

Examples

Copy CodeC#
var productView =
    from p in products
    join s in sales on p.ProductID equals s.ProductID into productSales
    select new
    {
        p.Name,
        SalesByCountry = productSales.AttachView(v =>
            from s in v
            group s by s.Country into countrySales
            select new
            {
                Country = countrySales.Key,
                SaleCount = countrySales.LiveSum(s => s.Quantity).Value
            })
    };

See Also